package com.bileetacrm;

import org.achartengine.ChartFactory;
import org.achartengine.GraphicalView;
import org.achartengine.chart.PointStyle;
import org.achartengine.model.XYMultipleSeriesDataset;
import org.achartengine.model.XYSeries;
import org.achartengine.renderer.XYMultipleSeriesRenderer;
import org.achartengine.renderer.XYSeriesRenderer;
import android.app.Activity;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Color;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;

public class BileetaDashbordActivity extends Activity {
	Button addnewlead, addnewevent;
	private String DATABASE_NAME = "bileetacrm.db";
	private SQLiteDatabase mydb;
	private static final int DATABASE_VERSION = 1;
	BileetaCRMDBLoader db;
	private GraphicalView mChart;

	private String[] mMonth = new String[] { "Jan", "Feb", "Mar", "Apr", "May",
			"Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };

	public void AddNewLead(View view) {
		Intent myIntent = new Intent(view.getContext(),
				BileetaFragmentActivity.class);
		startActivityForResult(myIntent, 0);
		overridePendingTransition(R.anim.anim_slide_in_left,
				R.anim.anim_slide_out_left);
	}

	public void AddNewEvent(View view) {
		Intent myIntent = new Intent(view.getContext(),
				BileetaAddNewEvent.class);
		startActivityForResult(myIntent, 0);
		overridePendingTransition(R.anim.anim_slide_in_left,
				R.anim.anim_slide_out_left);
	}

	public void ViewCallLogs(View view) {
		Intent myIntent = new Intent(view.getContext(),
				BileetaCallLogActivity.class);
		startActivityForResult(myIntent, 0);
		overridePendingTransition(R.anim.anim_slide_in_left,
				R.anim.anim_slide_out_left);
	}

	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		setContentView(R.layout.bileeta_dashbord_activity);

		openChart();

		/*addnewlead = (Button) findViewById(R.id.addnewlead);
		addnewlead.setOnClickListener(new View.OnClickListener() {
			public void onClick(View view) {
				Intent myIntent = new Intent(view.getContext(),
						BileetaFragmentActivity.class);
				startActivityForResult(myIntent, 0);
			}

		});
		addnewevent = (Button) findViewById(R.id.addnewevent);
		addnewevent.setOnClickListener(new View.OnClickListener() {
			public void onClick(View view) {
				Intent myIntent = new Intent(view.getContext(),
						BileetaAddNewEvent.class);
				startActivityForResult(myIntent, 0);
			}

		});*/

		// ViewCallLogs

	}

	private void openChart() {
		int[] x = { 1, 2, 3, 4, 5, 6, 7, 8 };
		int[] income = { 2000, 2500, 2700, 3000, 2800, 3500, 3700, 3800 };
		int[] expense = { 2200, 2700, 2900, 2800, 2600, 3000, 3300, 3400 };

		// Creating an XYSeries for Income
		XYSeries incomeSeries = new XYSeries("Leeds");
		// Creating an XYSeries for Expense
		XYSeries expenseSeries = new XYSeries("Events");
		// Adding data to Income and Expense Series
		for (int i = 0; i < x.length; i++) {
			incomeSeries.add(x[i], income[i]);
			expenseSeries.add(x[i], expense[i]);
		}

		// Creating a dataset to hold each series
		XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
		// Adding Income Series to the dataset
		dataset.addSeries(incomeSeries);
		// Adding Expense Series to dataset
		dataset.addSeries(expenseSeries);

		// Creating XYSeriesRenderer to customize incomeSeries
		XYSeriesRenderer incomeRenderer = new XYSeriesRenderer();
		incomeRenderer.setColor(Color.WHITE);
		incomeRenderer.setPointStyle(PointStyle.CIRCLE);
		incomeRenderer.setFillPoints(true);
		incomeRenderer.setLineWidth(2);
		incomeRenderer.setDisplayChartValues(true);

		// Creating XYSeriesRenderer to customize expenseSeries
		XYSeriesRenderer expenseRenderer = new XYSeriesRenderer();
		expenseRenderer.setColor(Color.YELLOW);
		expenseRenderer.setPointStyle(PointStyle.CIRCLE);
		expenseRenderer.setFillPoints(true);
		expenseRenderer.setLineWidth(2);
		expenseRenderer.setDisplayChartValues(true);

		// Creating a XYMultipleSeriesRenderer to customize the whole chart
		XYMultipleSeriesRenderer multiRenderer = new XYMultipleSeriesRenderer();
		multiRenderer.setXLabels(0);
		multiRenderer.setChartTitle("Leeds vs Events Dash Board");
		multiRenderer.setXTitle("Year 2014");
		multiRenderer.setYTitle("Scheduled Events");
		multiRenderer.setZoomButtonsVisible(true);
		for (int i = 0; i < x.length; i++) {
			multiRenderer.addXTextLabel(i + 1, mMonth[i]);
		}

		// Adding incomeRenderer and expenseRenderer to multipleRenderer
		// Note: The order of adding dataseries to dataset and renderers to
		// multipleRenderer
		// should be same
		multiRenderer.addSeriesRenderer(incomeRenderer);
		multiRenderer.addSeriesRenderer(expenseRenderer);

		// Getting a reference to LinearLayout of the MainActivity Layout
		LinearLayout chartContainer = (LinearLayout) findViewById(R.id.chart_container);

		// Creating a Line Chart
		mChart = (GraphicalView) ChartFactory.getLineChartView(
				getBaseContext(), dataset, multiRenderer);

		// Adding the Line Chart to the LinearLayout
		chartContainer.addView(mChart);

	}

	@Override
	public void onBackPressed() {
		Intent myIntent = new Intent(BileetaDashbordActivity.this,
				BileetaLoginActivity.class);
		startActivityForResult(myIntent, 0);
		// code here to show dialog
		super.onBackPressed(); // optional depending on your needs
	}

}
